package com.soft.javase.day06.regex;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/24
 */
public class Person {
    private String name;
    private String gender;
    private int age;
    private String qqNumber;

    public Person(String name, String gender, int age, String qqNumber) {
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.qqNumber = qqNumber;
    }

    // 验证QQ号是否合法
    public boolean isValidQQ() {
        // QQ号规则: 全数字，第一位非0，长度5-12位
        return qqNumber != null && qqNumber.matches("^[1-9]\\d{4,11}$");
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", gender='" + gender + '\'' +
                ", age=" + age +
                ", qqNumber='" + qqNumber + '\'' +
                '}';
    }

    public static void main(String[] args) {
        String text = "  anglebaby          女          18          515151511  ";

        String[] parts = text.trim().split(" +");

        if (parts.length == 4) {
            String name = parts[0];
            String gender = parts[1];
            int age = Integer.parseInt(parts[2]);
            String qqNumber = parts[3];

            Person person = new Person(name, gender, age, qqNumber);

            System.out.println("解析后的个人信息:");
            System.out.println(person);

            System.out.println("QQ号验证结果:");
            if (person.isValidQQ()) {
                System.out.println("QQ号 " + qqNumber + " 是合法的");
            } else {
                System.out.println("QQ号 " + qqNumber + " 不合法");
            }
        } else {
            System.out.println("文本格式不正确，无法解析");
        }
    }
}
